package de.koller.reason.render.ray;

import de.koller.oceanFramework.math.RVec3;

public class Ray {

	public final RVec3 a;
	public final RVec3 b;
	
	private Ray( RVec3 a, RVec3 b ) {
		this.a = a;
		this.b = b;
	}
	
	public static Ray create( float fov, float ratio, float x, float y, float farplane ) {
		float alpha = ((float)Math.PI - fov) / 2f;
		float d = (float)Math.tan( alpha ) * .5f;
		RVec3 a = new RVec3( 0, 0, -d );
		float k = farplane / d;
		RVec3 b = new RVec3( x * k, y * k, farplane ); 
		
		return new Ray( a, b );
	}
	
//	public static Ray create( float fov, float width, float height, int x, int y, float farplane ) {
//		float alpha = ((float)Math.PI - fov) / 2f;
//		float d = (float)Math.tan( alpha ) * (width / 2f);
//		RVec3 a = new RVec3( -width / 2f, -height / 2f, d );
//		RVec3 b = new RVec3( -x / 2f, -y / 2f, 0 ).sub( a );
//		b.mult( farplane / d );
//		b.sub( a );
//		a.set( -x / 2f, -y / 2f, 0 );
//		return new Ray( a, b );
//	}
	
}
